package com.yami.shop.common.config;

import com.yami.shop.common.bean.MinioProperties;
import com.yami.shop.common.util.MinioTemplate;
import io.minio.MinioClient;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@AllArgsConstructor
@Configuration
public class MinioConfig  {



    /**
     * minio
     * 配置文件
     */

    private final MinioProperties minioProperties;
    /**
     * MinIO 客户端
     */
    @Bean("minioClient")
    public MinioClient minioClient(){

            // 创建一个Minio的客户端对象

        return      MinioClient.builder()
                .endpoint(minioProperties.getEndpointUrl())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecreKey())
                .build();
    }

    //  初始化MinioTemplate，封装了一些MinIOClient的基本操作
    @Bean(name = "minioTemplate")
    public MinioTemplate minioTemplate() {
        return new MinioTemplate(minioClient(), this);

    }

    public String getBucketName() {
        return minioProperties.getBucketName();
    }
}
